package com.furongji.education.service.impl;

import com.furongji.common.domain.vo.CourseViewCountVo;
import com.furongji.education.domain.po.CourseViewLog;
import com.furongji.education.mapper.CourseViewLogMapper;
import com.furongji.education.service.CourseViewLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author furongji
 * @since 2025-06-02
 */
@Service
@RequiredArgsConstructor
public class CourseViewLogServiceImpl extends ServiceImpl<CourseViewLogMapper, CourseViewLog> implements CourseViewLogService {

    private final CourseViewLogMapper courseViewLogMapper;

    @Override
    public List<CourseViewCountVo> courseViewCount(String dateStr) {
        LocalDate date = LocalDate.parse(dateStr);
        LocalDateTime startDateTime = date.atStartOfDay();
        LocalDateTime endDateTime = date.plusDays(1).atStartOfDay();
        List<CourseViewCountVo> stats = courseViewLogMapper.courseViewCount(startDateTime, endDateTime);
        return stats;
    }
}
